#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdlib.h>
#include <string.h>
 
struct msgbuf
{
        long mtype;
        char mtest[128];
        char ID[4];
};
 
int main()
{
        struct msgbuf sendbuf,readbuf;
        int msgid;
        int readret;
        msgid = msgget(IPC_PRIVATE,0755);
        if(msgid == -1)
        {
                printf("create message queue failed!\n");
                return -1;
        }
        system("ipcs -q");
        printf("create message success msgid = %d\n",msgid);
        sendbuf.mtype = 100;
        printf("please input to message queue:\n");
 fgets(sendbuf.mtest,128,stdin);
        msgsnd(msgid,(void *)&sendbuf,strlen(sendbuf.mtest),0);
//      while(1);
//      msgctl(32769,IPC_RMID,NULL);
//      system("ipcs -q");
        // memset(readbuf.mtest,0,128);
        // readret = msgrcv(msgid,(void *)&readbuf,128,100,0);
        // printf("message is : %s\n",readbuf.mtest);
        // printf("total have %d byth\n",readret);
 
        return 0;
 
}